#include "tinyrpc/base/coroutine/coroutine.h"
#include <memory>
#include <string>
#include <iostream>
#include "tinyrpc/base//thread.h"
using namespace TinyRPC;

void task1(){
    std::cout<<"in coroutine1"<<std::endl;
    Coroutine::Yield();
    std::cout<<"in coroutine2"<<std::endl;
}

// 在线程内调用也正常
void task2(){
    std::cout<<"in thread coroutine1"<<std::endl;
    Coroutine::Yield();
    std::cout<<"in  thread coroutine2"<<std::endl;
}
void thread_func(){
    //Coroutine co2(task2);
    CoroutinePtr co2 = std::make_shared<Coroutine>(task2);
    co2->resume();
    std::cout<<"in thread"<<std::endl;
    co2->resume();
    std::cout<<"in thread2"<<std::endl;
}

int main(){
    {
        CoroutinePtr co1 = std::make_shared<Coroutine>(task1);
        co1->resume();
        std::cout<<"in main"<<std::endl;
        co1->resume();
    }
    

    Thread t(thread_func);
    t.start();
    t.join();

}